window.onload = function() {
    // 轮播图开始
    var oDiv = document.getElementById('play');
    var oBtn = oDiv.getElementsByTagName('ol')[0].getElementsByTagName('li');
    var oUl = oDiv.getElementsByTagName('ul')[0];
    var now = 0;

    for (var i = 0; i < oBtn.length; i++) {
        oBtn[i].index = i;
        oBtn[i].onmouseover = function() {
            now = this.index;

            tab();
        };
    }

    // 封装tab函数
    function tab() {
        for (var i = 0; i < oBtn.length; i++) {
            oBtn[i].className = '';
        }
        oBtn[now].className = 'active';

        startMove(oUl, {
            top: -460 * now,
        });
    }

    // 封装next函数，为自动播放准备
    function next() {
        now++;
        if (now == oBtn.length) {
            now = 0;
        }

        tab();
    }

    // 左右按钮
    var oBtnPrev = document.getElementById('prev');
    var oBtnNext = document.getElementById('next');

    oBtnPrev.onclick = function() {
        now--;
        if (now == -1) {
            now = oBtn.length - 1;
        }
        tab();
    };
    oBtnNext.onclick = function() {
        now++;
        if (now == oBtn.length) {
            now = 0;
        }

        tab();
    };

    // 自动播放
    var timer = setInterval(next, 3000);

    // 鼠标移入暂停自动播放
    oDiv.onmouseover = function() {
        clearInterval(timer);
    };
    oDiv.onmouseout = function() {
        timer = setInterval(next, 3000);
    };
    // 轮播图结束

    // 小米闪购——时分秒倒计时JS部分开始
    var CountDownTime = document.getElementById('count-down_time');
    var CountDownMinute = document.getElementById('count-down_minute');
    var CountDownSecond = document.getElementById('count-down_second');

    // 转化为两位小数
    function tow(n) {
        return n >= 0 && n < 10 ? '0' + n : '' + n;
    }

    function getDate() {
        var oDate = new Date(); //获取日期对象
        var oldTime = oDate.getTime(); //现在距离1970年的毫秒数
        var newDate = new Date('2021/10/19 00:00:00');
        var newTime = newDate.getTime(); //2019年距离1970年的毫秒数
        var second = Math.floor((newTime - oldTime) / 1000); //未来时间距离现在的秒数
        // var day = Math.floor(second / 86400); //整数部分代表的是天；一天有24*60*60=86400秒 ；
        second = second % 86400; //余数代表剩下的秒数；
        var hour = Math.floor(second / 3600); //整数部分代表小时；
        second %= 3600; //余数代表 剩下的秒数；
        var minute = Math.floor(second / 60);
        second %= 60;

        CountDownTime.innerHTML = tow(hour);
        CountDownMinute.innerHTML = tow(minute);
        CountDownSecond.innerHTML = tow(second);
    }
    getDate();
    setInterval(getDate, 1000);
    // 小米闪购——时分秒倒计时JS部分开结束

    // 小米闪购——秒杀JS部分开始
    var FlashBoxTime = document.getElementById('flash_box_time');

    function getSecondskilltime() {
        var oHours = new Date().getHours(); //获取小时

        if (oHours >= 0 && oHours < 10) {
            oHours = 00;
        } else if (oHours >= 10 && oHours < 14) {
            oHours = 10;
        } else if (oHours >= 14 && oHours < 20) {
            oHours = 14;
        } else if (oHours >= 20 && oHours < 22) {
            oHours = 20;
        } else if (oHours >= 22) {
            oHours = 22;
        }

        FlashBoxTime.innerHTML = oHours + ':00 场';
    }
    getSecondskilltime();
    setInterval(getSecondskilltime, 1000);
    // 小米闪购——秒杀JS部分结束

    // 视频部分，小三角开始
    var VideoBtn1 = document.getElementById('videobtn1');
    var VideoPlay1 = document.getElementById('videoplay1');
    var VideoBtn2 = document.getElementById('videobtn2');
    var VideoPlay2 = document.getElementById('videoplay2');
    var VideoBtn3 = document.getElementById('videobtn3');
    var VideoPlay3 = document.getElementById('videoplay3');
    var VideoBtn4 = document.getElementById('videobtn4');
    var VideoPlay4 = document.getElementById('videoplay4');

    function video(obj1, obj2) {
        obj1.onmouseover = function() {
            obj2.style.background = '#ff6700';
            obj2.style.borderColor = '#ff6700';
        };
        obj1.onmouseout = function() {
            obj2.style.background = 'transparent';
            obj2.style.borderColor = '#fff';
        };
    }

    video(VideoBtn1, VideoPlay1);
    video(VideoBtn2, VideoPlay2);
    video(VideoBtn3, VideoPlay3);
    video(VideoBtn4, VideoPlay4);
    // 视频部分，小三角结束

    // 右侧悬浮框——回到顶部开始
    var goTop = document.getElementById('gotop');

    // setInterval(function() {
    //     if (document.documentElement.scrollTop > document.documentElement.clientHeight) {
    //         goTop.style.display = 'block';
    //     } else {
    //         goTop.style.display = 'none';
    //     }
    // }, 100);

    // onscroll事件：当页面滚动的时候会发生
    window.onscroll = function() {
        if (document.documentElement.scrollTop > document.documentElement.clientHeight) {
            goTop.style.display = 'block';
        } else {
            goTop.style.display = 'none';
        }
    };

    // 右侧悬浮框——回到顶部结束

    // 家电部分开始
    var homeelec_oUl = document.getElementById('homeelec_title');
    var homeelec_oLi = homeelec_oUl.getElementsByTagName('li');
    var homeelecOne = document.getElementById('homeelec_box_right_one');
    var homeelecTwo = document.getElementById('homeelec_box_right_two');

    for (var i = 0; i < homeelec_oLi.length; i++) {
        homeelec_oLi[i].onmouseover = function() {
            for (var i = 0; i < homeelec_oLi.length; i++) {
                homeelec_oLi[i].children[0].className = '';
            }
            this.children[0].className = 'homeelec_active';

            if (this == homeelec_oLi[0]) {
                homeelecOne.style.display = 'block';
                homeelecTwo.style.display = 'none';
            } else if (this == homeelec_oLi[1]) {
                homeelecTwo.style.display = 'block';
                homeelecOne.style.display = 'none';
            }
        };
    }
    // 家电部分结束

    // 智能部分开始
    var Intelligent_oUl = document.getElementById('intelligent_title');
    var Intelligent_oLl = Intelligent_oUl.getElementsByTagName('li');
    var intelligent_One = document.getElementById('intelligent_box_right_one');
    var intelligent_Two = document.getElementById('intelligent_box_right_two');
    var intelligent_Three = document.getElementById('intelligent_box_right_three');

    for (var i = 0; i < Intelligent_oLl.length; i++) {
        Intelligent_oLl[i].onmouseover = function() {
            for (var i = 0; i < Intelligent_oLl.length; i++) {
                Intelligent_oLl[i].children[0].className = '';
            }
            this.children[0].className = 'intelligent_active';

            if (this == Intelligent_oLl[0]) {
                intelligent_One.style.display = 'block';
                intelligent_Two.style.display = 'none';
                intelligent_Three.style.display = 'none';
            } else if (this == Intelligent_oLl[1]) {
                intelligent_One.style.display = 'none';
                intelligent_Two.style.display = 'block';
                intelligent_Three.style.display = 'none';
            } else if (this == Intelligent_oLl[2]) {
                intelligent_One.style.display = 'none';
                intelligent_Two.style.display = 'none';
                intelligent_Three.style.display = 'block';
            }
        };
    }
    // 智能部分结束

    // 搭配部分开始
    var match_oUl = document.getElementById('match_title');
    var match_oLi = match_oUl.getElementsByTagName('li');
    var match_One = document.getElementById('match_box_right_one');
    var match_Two = document.getElementById('match_box_right_two');

    for (var i = 0; i < match_oLi.length; i++) {
        match_oLi[i].onmouseover = function() {
            for (var i = 0; i < match_oLi.length; i++) {
                match_oLi[i].children[0].className = '';
            }
            this.children[0].className = 'match_active';

            if (this == match_oLi[0]) {
                match_One.style.display = 'block';
                match_Two.style.display = 'none';
            } else if (this == match_oLi[1]) {
                match_One.style.display = 'none';
                match_Two.style.display = 'block';
            }
        };
    }
    // 搭配部分结束

    // 配件部分开始
    var accessories_oUl = document.getElementById('accessories_title');
    var accessories_oLi = accessories_oUl.getElementsByTagName('li');
    var accessories_One = document.getElementById('accessories_box_right_one');
    var accessories_Two = document.getElementById('accessories_box_right_two');

    for (var i = 0; i < accessories_oLi.length; i++) {
        accessories_oLi[i].onmouseover = function() {
            for (var i = 0; i < accessories_oLi.length; i++) {
                accessories_oLi[i].children[0].className = '';
            }
            this.children[0].className = 'match_active';

            if (this == accessories_oLi[0]) {
                accessories_One.style.display = 'block';
                accessories_Two.style.display = 'none';
            } else if (this == accessories_oLi[1]) {
                accessories_One.style.display = 'none';
                accessories_Two.style.display = 'block';
            }
        };
    }
    // 配件部分结束

    // 周边样式开始
    var circum_oUl = document.getElementById('circum_title');
    var circum_oLi = circum_oUl.getElementsByTagName('li');
    var circum_One = document.getElementById('circum_box_right_one');
    var circum_Two = document.getElementById('circum_box_right_two');

    for (var i = 0; i < circum_oLi.length; i++) {
        circum_oLi[i].onmouseover = function() {
            for (var i = 0; i < circum_oLi.length; i++) {
                circum_oLi[i].children[0].className = '';
            }
            this.children[0].className = 'circum_active';

            if (this == circum_oLi[0]) {
                circum_One.style.display = 'block';
                circum_Two.style.display = 'none';
            } else if (this == circum_oLi[1]) {
                circum_One.style.display = 'none';
                circum_Two.style.display = 'block';
            }
        };
    }
    // 周边样式结束
}